<template>
    <div class="loan-in-repayment">
        <!-- wrapper -->
        <div class="wrapper">
            <div class="loan-repayment__list">
                <div class="loan-repayment__item">
                    <check-box class='loan-repayment__checkbox'></check-box>
                    <div class="loan-repayment__info">
                        <div class="loan-repayment__period">
                            <p class="money">85.00</p>
                            <p class="period">[1/6期] 李彬 - 出租</p>
                        </div>
                        <p class="loan-repayment__time">剩余3天</p>
                    </div>
                </div>
                <div class="loan-repayment__item">
                    <check-box class='loan-repayment__checkbox'></check-box>
                    <div class="loan-repayment__info">
                        <div class="loan-repayment__period">
                            <p class="money">85.00</p>
                            <p class="period">[1/6期] 李彬 - 出租</p>
                        </div>
                        <p class="loan-repayment__time">剩余3天</p>
                    </div>
                </div>
                <div class="loan-repayment__item">
                    <check-box class='loan-repayment__checkbox'></check-box>
                    <div class="loan-repayment__info">
                        <div class="loan-repayment__period">
                            <p class="money">85.00</p>
                            <p class="period">[1/6期] 李彬 - 出租</p>
                        </div>
                        <p class="loan-repayment__time">剩余3天</p>
                    </div>
                </div>
                <div class="loan-repayment__item">
                    <check-box class='loan-repayment__checkbox'></check-box>
                    <div class="loan-repayment__info">
                        <div class="loan-repayment__period">
                            <p class="money">85.00</p>
                            <p class="period">[1/6期] 李彬 - 出租</p>
                        </div>
                        <p class="loan-repayment__time">剩余3天</p>
                    </div>
                </div>
            </div>
        </div>
            
        <!-- footer -->
        <footer class="footer-button">
            <div class="loan-repayment__item">
                <check-box class='loan-repayment__checkbox'></check-box>
                <div class="loan-repayment__info">
                    <div class="loan-repayment__period">
                        <p class="money">85.00</p>
                        <p class="period">待付款</p>
                    </div>
                    <span class="button short" @click='show_modal_loan_detail = true'>立即还款</span>
                </div>
            </div>
        </footer>

        <pay-password
            :show='showPayPassword'
            :status='payStatus'
            @close='showPayPassword=false'
            @finish='payFinish'></pay-password>

        <modal 
            :show='show_modal_loan_detail'
            mode='bottom'
            @close='show_modal_loan_detail = false'>
            <div class='modal-pay-detail'>
                <div class="modal-pay-detail__header">支付详情</div>
                <ul class="modal-pay-detail__main">
                    <li class="modal-pay-detail__item">
                        <p class="key">金额</p>
                        <div class="value">
                            <p class='fee'>85.00元</p>
                        </div>
                    </li>
                    <li class="modal-pay-detail__item">
                        <p class="key">支付方式</p>
                        <div class="value">
                            <p class='bank'>中国光大银行(7631)</p>
                            <p class='people'>持卡人: 周*</p>
                        </div>
                    </li>
                    <li class="modal-pay-detail__item">
                        <p class="key">手续费</p>
                        <div class="value">
                            <p class='money'>2.50元</p>
                            <p class='tips'>支付金额大于500.00元免手续费</p>
                        </div>
                    </li>
                </ul>
                <div class="modal-pay-detail__footer">
                    <span class="button" @click='confirmPay'>确认支付 87.50元</span>
                </div>
            </div>
        </modal>
    </div>
</template>

<script>
    import { Promise } from 'es6-promise'
    import footerBar from '../components/FooterBar.vue'
    import selectGroup from '../components/SelectGroup.vue'
    import selectOption from '../components/SelectOption.vue'
    import radioGroup from '../components/RadioGroup.vue'
    import areaSelect from '../components/AreaSelect.vue'
    import radio from '../components/Radio.vue'
    import loading from '../components/Loading.vue'
    import checkBox from '../components/CheckBox.vue'
    import toolTip from '../components/ToolTip.vue'
    import modal from '../components/Modal.vue'
    import confirm from '../components/Confirm.vue'
    import buttonLoading from '../components/ButtonLoading.vue'
    import pagination from '../components/Pagination.vue'
    import payPassword from '../components/PayPassword.vue'
    import pickerList from '../components/PickerList.vue'
    import tabBox from '../components/TabBox.vue'
    import tab from '../components/Tab.vue'
    import  { mapGetters, mapActions }  from 'vuex'
    import { addLenderValidation, resetAccountPasswordValidation, operatorEditValidation } from '../validation/validation'
    import { allApi, lenderApi } from '../api/api'
    import moment from 'moment'

    export default {
        components:{
            footerBar,
            selectGroup,
            selectOption,
            radioGroup,
            radio,
            checkBox,
            areaSelect,
            loading,
            toolTip,
            modal,
            confirm,
            buttonLoading,
            pagination,
            payPassword,
            pickerList,tabBox,
            tab
        },
        data() {
            return {
                showPayPassword:false,
                payways:[{
                    value:0,
                    display:'还款方式1'
                },{
                    value:1,
                    display:'还款方式2'
                },{
                    value:2,
                    display:'还款方式3'
                }],
                show_modal_loan_detail:true,
                argeement:true,
                payway:-1,
                payPasswordShow:false,
                payStatus:'',
                password:'',
                placeholder:'--',
                userCount:'',
                listInfo:{},
                records:[],
                loading:true,
                loading_count:true,
            }
        },
        computed:{
            ...mapGetters([
                'msgTip',
                'localInfo'
            ]),
            currentPage(){
                if(_.isEmpty(this.listInfo)) return 1
                return this.listInfo.pageNum
            },
            hasUserCount(){
                return !_.isEmpty(this.userCount)
            },
            noEditObject(){
                return _.isEmpty(this.editObject)
            },
            noInvoiceInfo(){
                return _.isEmpty(this.invoiceInfo)
            }
        },
        methods:{
            // actions
            ...mapActions([
                'showLoading',
                'hideLoading',
                'setMsgTip'
            ]),

            // filters
            timestampToDate(timestamp){
                if(!timestamp) return this.placeholder
                return moment(timestamp).format('YYYY-MM-DD')
            },

            // function

            payFinish(){
                setTimeout(()=>{
                    this.payStatus = 'success'
                },2000)
            },
            confirmPay(){
                this.show_modal_loan_detail = false
                this.showPayPassword = true
            },
            goUse(){
                this.$router.push({
                    name:'loan-in-want-use'
                })
            },
            goSuccess(){
                this.$router.push({
                    name:'loan-in-success'
                })
            },
            test(){
                console.log(1)
            },
            goPay(){
                this.payStatus = true
                console.log(1)
            },
            goDetail(item){
                this.$router.push({
                    name:'user-detail',
                    params:{
                        id:item.userId,
                    }
                })
            },
            getList(num){
                this.loading = true
                allApi.userList(num)
                .then(result=>{
                    this.loading = false
                    this.listInfo = result
                    this.records = result.records
                    if(result.totalPage < result.pageNum){
                        this.getList(result.totalPage)
                    }
                })
                .catch(error => {
                    console.error(error)
                    this.loading = false
                })
            },
            getAccount(){
                this.loading_count = true
                allApi.userCount()
                .then(result=>{
                    this.loading_count = false
                    this.userCount = result
                })
                .catch(error => {
                    console.error(error)
                    this.loading_count = false
                })
            },
        },
        created(){
            
        }
    }
</script>

<style lang="scss">
    @import "../sass/variables";
    @import "../sass/extends";
    @import "../sass/mixins";
    .loan-in-repayment{
        .wrapper{
            padding-bottom: 100px;
        }
        .loan-repayment__list{
            background-color: #fff;
        }
        .loan-repayment__item{
            display: flex;
            align-items:center;
            position: relative;
            &:after{
                content:'';
                position: absolute;
                bottom:0;
                right:0;
                left:56px;
                border-top: 1px solid $sectionColor;
            }
            &:last-child{
                &:after{
                    display: none;
                }
            }
        }
        .loan-repayment__checkbox{
            padding:24px 32px 24px 16px ;
        }
        .loan-repayment__info{
            flex:1;
            display: flex;
            justify-content: space-between;
        }
        .loan-repayment__period{
            .money{
                @extend %font-body1;
                color:$importColor;
            }
            .period{
                @extend %font-caption;
            }
        }
        .loan-repayment__time{
            @extend %font-caption;
            padding-right: 24px;
        }
        .footer-button{
            padding: 0;
            .loan-repayment__item{
                flex:1;
                .money{
                    @extend %font-title;
                    color:$orange;
                }
            }
            .loan-repayment__info{
                align-items:center;
            }
            .button{
                margin-right:16px;
            }
        }
        .modal-pay-detail__header{
            @extend %font-title;
            color:$importColor;
            padding-bottom: 16px;
        }
        .modal-pay-detail__item{
            height: 64px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .key{
                @extend %font-subhead;
                color:$importColor;
            }
            .value{
                @extend %font-title;
                text-align: right;
                .fee{
                    color:$orange;
                }
                .bank{
                    @extend %font-subhead;
                }
                .people{
                    @extend %font-caption;
                }
                .money{
                    @extend %font-subhead;
                    color:$orange;
                }
                .tips{
                    @extend %font-caption;
                }
            }
        }
        .modal-pay-detail__footer{
            display: flex;
            justify-content: flex-end;
            padding-top: 14px;
            .button{
                margin: 0;
            }
        }
    }

</style>
